package org.jeecg.modules.demo.zc.rentCar.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.zc.rentCar.entity.RentCar;
import org.jeecg.modules.demo.zc.rentCar.service.IRentCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 外租车辆
 */
@Api(tags="rentCar")
@RestController
@RequestMapping("/zc/RentCar")
@Slf4j
public class RentCarController extends JeecgController<RentCar, IRentCarService> {

    @Autowired
    private IRentCarService rentCarService;

    /**
     * 分页列表查询
     *
     * @param rentCar
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "rentCar-分页列表查询")
    @ApiOperation(value="rentCar-分页列表查询", notes="rentCar-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<RentCar>> queryPageList(RentCar rentCar,
                                                @RequestParam(name="orgCode", required = false) String orgCode,
                                                @RequestParam(name="userid") String userid,
                                                @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                HttpServletRequest req) {

        if(orgCode == null){
            orgCode = "";
        }

        Integer orgId = rentCarService.getOrgId(orgCode);
        List<Integer> orgIdList = rentCarService.getparentOrgIds(orgId);
        orgIdList.add(orgId);

        QueryWrapper<RentCar> queryWrapper = QueryGenerator.initQueryWrapper(rentCar, req.getParameterMap());
        queryWrapper.clear();
        queryWrapper.eq("CAR_BELONG", 2);
        queryWrapper.in("ORG_ID",orgIdList);
        Page<RentCar> page = new Page<RentCar>(pageNo, pageSize);
        IPage<RentCar> pageList = rentCarService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
}
